package cn.itcast.order.service;

import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    public Order queryOrderById(Long orderId) {
        Order order = new Order();
        order.setId(orderId);
        order.setUserId(1L);
        order.setName("订单名称 1");
        order.setNum(2);
        order.setPrice(19L);
        // 远程调用
        // url路径
        String url = "http://user-service/user/" + order.getUserId();
        // 发送http请求，实现远程调用
        User user = restTemplate.getForObject(url, User.class);
        order.setUser(user);
        return order;
    }
}